<template>
	<view style="background: #166BE6;min-height: 100vh;padding-bottom: 100rpx;">
		<view style="position: relative;">
			<image :src="$ftpUrl('/drwaBg.png')" style="width: 100%;height: 600rpx;"></image>
			<view
				style="text-align: center;color: #fff;position: absolute;left: 50%;top: 80%;transform: translate(-50%,-50%);">
				<view>转发分享可获得次数</view>
				<view style="padding: 7rpx 30rpx; background: #3780EA;margin: 40rpx;border-radius: 20rpx;">剩余次数{{num}}次
				</view>
			</view>
		</view>

		<view style="">

			<lottery v-if="prizeList.length " ref="pt-lottery" :lotteryBg="$ftpUrl('/pan.png')"
				:lotteryBtn="$ftpUrl('/zhen.png')" :times="1000" :prizeList="prizeList" @start="start" @end="end">
			</lottery>
		</view>

	</view>
</template>

<script>
	import lottery from '@/components/lottery/lottery.vue';
	export default {
		components: {
			lottery
		},
		data() {
			return {
				// prizeName prizeIcon
				prizeList: [],
				item: '',
				num: ''
			}
		},
		onLoad() {
			this.getAwards()
			this.getlotteryNum()
		},
		methods: {



			getlotteryNum() {
				this.$u.post('/user/lotteryNum', {}).then(res => {
					this.num = res.surplus;
				}).catch(err => {

				})
			},
			getAwards() {
				this.$u.post('/index/awards', {}).then(res => {
					res.forEach(item => {
						item.prizeName = item.awards
					})
					this.prizeList = res;
				}).catch(err => {

				})
			},


			start() {

				this.$u.post('/user/lottery', {}).then(res => {

					this.prizeList.forEach((item, index) => {
						if (item.id == res) {
							this.$refs['pt-lottery'].init(index);
							this.item = item;
						}
					})

                    this.getlotteryNum()
				}).catch(err => {

				})



			},
			end(e) {
			 this.$u.toast(this.item.awards)
			}
		},
		onShareAppMessage() {
			this.$u.post('/user/share', {}).then(res => {
				this.getlotteryNum()
			}).catch(err => {

			})
		}
	}
</script>

<style>
</style>
